package com.cloud.pole.shop.service.goods.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cloud.pole.common.util.jwt.IJWTInfo;
import com.cloud.pole.common.util.jwt.JwtTokenUtil;
import com.cloud.pole.shop.biz.goods.ShopGoodsGroupBiz;
import com.cloud.pole.shop.model.entity.goods.ShopGoodsAdmin;
import com.cloud.pole.shop.model.entity.goods.ShopGoodsGroup;
import com.cloud.pole.shop.service.goods.GoodsGroupService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import javassist.expr.NewArray;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Service
public class GoodsGroupServiceImpl implements GoodsGroupService {

	@Autowired
	ShopGoodsGroupBiz shopGoodsGroupBiz;
	
	@Override
	public List<ShopGoodsGroup> selectAllShopGroup() {
		
		return shopGoodsGroupBiz.selectByAll();
	}

	@Override
	public PageInfo<ShopGoodsGroup> selectPageShopGoodsGroupAdminList(Integer pageNo, Integer pageSize)
			throws Exception {
		PageHelper.startPage(pageNo, pageSize);
		List<ShopGoodsGroup> selectByShopGoodsGroup = shopGoodsGroupBiz.selectByShopGoodsGroup();
		PageInfo<ShopGoodsGroup> page = new PageInfo<ShopGoodsGroup>(selectByShopGoodsGroup);
		return page;
	}

	@Override
	public void addShopGoodsGroup(String token, ShopGoodsGroup shopGoodsGroup) throws Exception {
		IJWTInfo jwtInfo = JwtTokenUtil.getInfoFromToken(token);
		shopGoodsGroup.setCreateTime(new Date());
		shopGoodsGroup.setCreateUserId(jwtInfo.getId());
		shopGoodsGroup.setMerchantId(1);
		shopGoodsGroupBiz.createShopGoods(shopGoodsGroup);
		
	}

	@Override
	public ShopGoodsGroup selectById(Integer groupId) throws Exception {
		
		return shopGoodsGroupBiz.selectGroup(groupId);
	}

	@Override
	public void updateGroup(String token, ShopGoodsGroup shopGoodsGroup) throws Exception {
		IJWTInfo jwtInfo = JwtTokenUtil.getInfoFromToken(token);
		shopGoodsGroup.setModifyTime(new Date());
		shopGoodsGroup.setModifyUserId(jwtInfo.getId());
		shopGoodsGroupBiz.updateShopGroup(shopGoodsGroup);
	}

	@Override
	public void deteGroup(Integer groupId) throws Exception {
		ShopGoodsGroup selectGroup = shopGoodsGroupBiz.selectGroup(groupId);
		shopGoodsGroupBiz.deleteGroups(selectGroup);
	}

	@Override
	public List<ShopGoodsGroup> selectByShop(Integer shopId) throws Exception {
		
		return shopGoodsGroupBiz.selectByShopsStatus(shopId);
	}


	

}
